package com.woniu.publisher;

import com.woniu.utils.ConstantUtil;
import com.woniu.utils.RabbitMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class SurgeryPublisher {
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Resource
    private RabbitMessageUtil rabbitMessageUtil;

    public void sendSurgeryReminder(String surgeryInfo) {
        try {
            log.info("发送手术提醒：{}", surgeryInfo);

            rabbitTemplate.convertAndSend(
                    ConstantUtil.EXCHANGE_SURGERY_REMINDER,
                    ConstantUtil.ROUTING_KEY_SURGERY_REMINDER,
                    surgeryInfo,
                    msg -> {
                        msg.getMessageProperties().setDelay(ConstantUtil.SURGERY_REMINDER_DELAY);
                        return msg;
                    });

        } catch (Exception e) {
            log.error("发送手术提醒失败：", e);
        }
    }
}
